package eli.turchinsky.software.agame;


import eli.turchinsky.software.agame.enteties.*;
import eli.turchinsky.software.agame.hood.LevelContainer;
import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {
	LevelContainer lc;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(new GamePanel(this));
		lc=new LevelContainer();
		Man.getInstance().init(80,30,getResources());
		lc.add(Man.getInstance());
		lc.add(new Star(getResources()));
		//lc.add(new Block(40,40,40,40,getResources()));
	}

	class GamePanel extends DrawablePanel {	
		private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		public GamePanel(Context context) {
			super(context);
		}

		@Override
		public void draw(Canvas canvas) {
			super.onDraw(canvas);
			paint.setStyle(Paint.Style.FILL);
			paint.setColor(Color.parseColor("#87CEEB"));
			canvas.drawRect(0, 0, getWidth(), getHeight(),paint);
			lc.draw(canvas);			
		}		
		public boolean onTouchEvent(MotionEvent event){
			if(event!=null)
				if(event.getY()<this.getHeight()*1/3)
					Man.getInstance().jump();
				else if(event.getY()<this.getHeight()*2/3)
					Man.getInstance().left();
				else
					Man.getInstance().jump();
			return true;
		}
		public void init() {

		}
		public void update(long gameTime) {			
			lc.update(gameTime);
		}
	}

}